<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>跳转中……</title>
    <style>
        .middle{
            display: block;
            width: 50%;
            margin: 30% auto;
            text-align: center;
        }
    </style>
</head>
<body>
<div class="middle">正在跳转……</div>

<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<script src="js/common.js"></script>
<script src="https://cdn.bootcss.com/layer/3.0.1/layer.min.js"></script>
<script type="application/javascript">
    /*function getopenid() {
        openid = window.localStorage.getItem("openid");
        if(openid == null || openid == undefined || openid == '') {
            getCode();
        }
    }

    function getCode() {
        var code = Common.queryGetParam('code');
        if(code == null || code == undefined || code == '') {
            location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx95bdc635798fcfe4&redirect_uri="+window.location.href+"&response_type=code&scope=snsapi_base#wechat_redirect";
            return;
        }
        var paramStr = {};
        paramStr.code = code;
        var params = {};
        params.paramStr = JSON.stringify(paramStr);
        Common.ajaxWithParam("/fenful/api/v1/common/getWxUserOpenId", params, function(data) {
            //console.log(data);
            window.localStorage.setItem("openid", data.openid);

        });
    }
    function openIdLogin(){
        var openid = window.localStorage.getItem("openid");
        if(openid == null || openid == undefined || openid == '') {
            getCode();
            return;
        }
        //拿到openid直接登录
        var p = {};
        var json = {};
        json.wxOpenId = openid;
        p.paramStr = JSON.stringify(json);
        //后台利用openId登录
        Common.ajaxWithParamBack("/fenful/api/v1/login/wxOpenIdLogin", p, function(obj) {
            //如果手机号和token成功返回，直接跳活动页面，否则跳登录页
            var _path = window.localStorage.getItem("_path");
            if(!_path){
                _path = "/fenful/h5/uploadImg.html";
            }

            if(obj.code == "200"){
                var data = eval('(' + obj.data + ')');
                var token = data.token;
                var phoneNum = data.phoneNum;

                if(token&&phoneNum){
                    window.localStorage.setItem("_phoneNum", phoneNum);
                    window.localStorage.setItem("_token", token);
                    window.location.href=_path;
                }else{
                    window.location.href="/fenful/h5/login.html";
                }
            }else{
                window.location.href="/fenful/h5/login.html";
            }

        });
    }*/

    //直接token登录，没有就短信登录
    function checkToken(){
        var phoneNum = Common.queryGetParam("phoneNum");
        var token = Common.queryGetParam("token");
        if(!phoneNum){
            phoneNum = window.localStorage.getItem("phoneNum");
        }
        if(!token){
            token = window.localStorage.getItem("token");
        }
        if(!phoneNum||!token){
            window.location.href="/fenful/h5/login2.html";
        }
        var _path = window.localStorage.getItem("_path");
        if(!_path){
            _path = Common.queryGetParam("_path");
        }
        //token登录
        var paramStr = {};
        paramStr.phoneNum=phoneNum;
        paramStr.token=token;
        var params = {};
        params.paramStr = JSON.stringify(paramStr);
        $.ajax({
            headers: {"phone":phoneNum,"token":token},
            method: "POST",
            data:params,
            url:'/fenful/api/v1/user/getUser',
            datatype: "json",
            success: function(re) {
                //token有效直接回跳
                var data=JSON.parse(re.data);
                if(data.id){
                    window.location.href = _path;
                }
            },
            error: function(re) {
                //token无效，跳登录
                window.location.href="/fenful/h5/login2.html?_path="+_path;

            }
        })

    }
    $(function () {
        checkToken();
    })
</script>
</body>
</html>